The OpenDefaultComponent , OpenComponent , and CloseComponent functions allow your application to gain access to and release components. Your application must open a component before it can use the services provided by that component. Similarly, your application must close the component when it is finished using the component.
You can use the OpenDefaultComponent function to open a component of a specified component type and subtype. You do not have to supply a component description record or call the FindNextComponent function to use this function.
You use the OpenComponent function to gain access to a specified component. To use this function, your application must have previously obtained a component identifier for the desired component by using the FindNextComponent function. (If your application registers a component, it can also obtain a component identifier from the RegisterComponent or RegisterComponentResource function.)
Once you are finished using a component, use the CloseComponent function to release the component.
The OpenDefaultComponent function allows your application to gain access to the services provided by a component. Your application must open a component before it can call any component functions. You specify the component type and subtype values of the component to open. The Component Manager searches for a component that meets those criteria. If you want to exert more control over the selection process, you can use the FindNextComponent and OpenComponent functions.
FUNCTION OpenDefaultComponent (componentType: OSType;
componentSubType: OSType)
: ComponentInstance;
The OpenDefaultComponent function searches its list of registered components for a component that meets the search criteria. If it finds a component that matches the search criteria, OpenDefaultComponent opens a connection to the component and returns a component instance. The returned component instance identifies your application's connection to the component. You must supply this component instance whenever you call the functions provided by the component. When you close the component, you must also supply this component instance to the CloseComponent function.
If more than one component in the list of registered components meets the search criteria, OpenDefaultComponent opens the first one that it finds in its list.
If it cannot open the specfied component, the OpenDefaultComponent function returns a function result of NIL .
For an example that opens a component using the OpenDefaultComponent function, see "Opening a Connection to a Default Component," .
The OpenComponent function allows your application to gain access to the services provided by a component. Your application must open a component before it can call any component functions. You specify the component with a component identifier that your application previously obtained from the FindNextComponent function.
Alternatively, you can use the OpenDefaultComponent function, as previously described, to open a component without calling the FindNextComponent function.
Note that your application may maintain several connections to a single component, or it may have connections to several components at the same time.
FUNCTION OpenComponent (aComponent: Component): ComponentInstance;
The OpenComponent function returns a component instance. The returned component instance identifies your application's connection to the component. You must supply this component instance whenever you call the functions provided by the component. When you close the component, you must also supply this component instance to the CloseComponent function.
If it cannot open the specfied component, the OpenComponent function returns a function result of NIL .
For examples of opening a specific component by using the FindNextComponent and OpenComponent functions, see Listing 1 and Listing 2 , respectively. For a description of the FindNextComponent function, see FindNextComponent .
The CloseComponent function terminates your application's access to the services provided by a component. Your application specifies the connection to be closed with the component instance returned by the OpenComponent or OpenDefaultComponent function.
FUNCTION CloseComponent
(aComponentInstance: ComponentInstance): OSErr;
The CloseComponent function closes only a single connection. If your application has several connections to a single component, you must call the CloseComponent function once for each connection.
For a description of the OpenDefaultComponent and OpenComponent functions, see OpenDefaultComponent and OpenComponent , respectively.